var api = require('../../utils/api.js')

Page({
    data: {
        list: [],
        nickname:''
    },
    onLoad() {

    },
    onShow() {
        var that=this;

        let user = wx.getStorageSync('user');
        if (!user) {
            wx.navigateTo({
                url: '/pages/login/login'
            });
        }

        api.get({
            url: 'user/index',
            data: {},
            success: data => {
                console.log(data.data);

                that.setData({user: data.data});
            }
        });

    

    },

    getqrcode(){
        api.get({
            url: 'wxapp/getqrcode',
            data: {},
            success: data => {
               var img=data.data;

          
                    wx.previewImage({
                        current: img, // 当前显示图片的http链接
                        urls: [img] // 需要预览的图片http链接列表
                    });
            
                

            }
        });

    },
    zhifu(){

        api.get({
            url: 'wxpay/pays',
            data: {},
            success: data => {
                if(data.code!=1){
                    wx.showToast({
                      title: data.msg,icon:'none'
                    })

                    return false;
                }
                wx.requestPayment({
                    timeStamp:data.data.timeStamp,
                    nonceStr: data.data.nonceStr,
                    package: data.data.package,
                    signType: 'MD5',
                    paySign: data.data.paySign,
                    success (res) {
                        wx.reLaunch({
                            url: '/pages/myorder/index',
                          })
                     },
                    fail (res) {
                        console.log('error',res)
                        wx.reLaunch({
                            url: '/pages/myorder/index',
                          })
                     }
                })

            }
        });

    }
});